package com.gitee.grower.util.germ

import com.germ.germplugin.api.dynamic.gui.GermGuiLabel
import com.gitee.grower.util.germ.germ.GermPartDSL
import ink.ptms.chemdah.util.conf
import taboolib.library.configuration.ConfigurationSection

class GermLabelDSL : GermPartDSL<GermGuiLabel>() {

    override val type = "label"

    var texts = mutableListOf<String>()
    var align = "left"
    var scale = "1"
    var popTime = ""
    var shadow = false
    var splitWidth : String? = null
    var animations = mutableListOf<String>()

    override fun infuse(config: ConfigurationSection) {
        name = config.name

        config.getString("locationX")?.let { locationX = it }
        config.getString("locationY")?.let { locationY = it }
        config.getString("locationZ")?.let { locationZ = it }
        config.getString("align")?.let { align = it }
        config.getString("scale")?.let { scale = it }
        config.getString("popTime")?.let { popTime = it }

        splitWidth = conf.getString("splitWidth")
        texts += config.getStringList("texts")
        animations += config.getStringList("animations")
        shadow = config.getBoolean("shadow")
        enable = config.getBoolean("enable")
    }

    override fun create(): GermGuiLabel {
        return GermGuiLabel(name).also {
            it.align = align
            it.enable = enable
            it.isShadow = shadow
            animations.forEach(it::addAnimation)
            it.texts = texts
            it.scale = scale
            it.popTime = popTime
            it.locationX = locationX
            it.locationY = locationY
            it.locationZ = locationZ
            it.splitWidth = splitWidth
        }
    }

}